package com.pda.gongpin.presenter;

import com.pda.gongpin.bean.AbnormalDataByContainerBean;
import com.pda.gongpin.bean.DropDownByEntryNoBean;
import com.pda.gongpin.contract.AbnormalCheckContract;
import com.pda.gongpin.net.NetUtils;
import com.wangshen.base.net.bean.BaseAppEntity;
import com.wangshen.base.ui.mvp.base.presenter.BasePresenter;

import java.util.List;

import io.reactivex.functions.Consumer;

public class AbnormalCheckPresenter extends BasePresenter<AbnormalCheckContract.View> implements  AbnormalCheckContract.Presenter{
    @Override
    public void getAbnormalDataByContainer(String container) {
        NetUtils.geApi().getAbnormalDataByContainer(container)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<AbnormalDataByContainerBean>>() {
                    @Override
                    public void accept(BaseAppEntity<AbnormalDataByContainerBean> abnormalDataByContainerBeanBaseAppEntity) throws Exception {
                        getView().setData(abnormalDataByContainerBeanBaseAppEntity.getData());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }

    @Override
    public void getArticleIdDropDownByEntryNo(String entryNo) {
        NetUtils.geApi().getArticleIdDropDownByEntryNo(entryNo)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<List<DropDownByEntryNoBean>>>() {
                    @Override
                    public void accept(BaseAppEntity<List<DropDownByEntryNoBean>> listBaseAppEntity) throws Exception {
                        getView().setSelectData(listBaseAppEntity.getData());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }

    @Override
    public void abnormalConfirm(String id, String newEntryNumberId, String boxNmu, String piecesNum) {
        NetUtils.geApi().abnormalConfirm(id, newEntryNumberId, boxNmu, piecesNum)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<List<DropDownByEntryNoBean>>>() {
                    @Override
                    public void accept(BaseAppEntity<List<DropDownByEntryNoBean>> listBaseAppEntity) throws Exception {
                        getView().showMessage(listBaseAppEntity.getMsg());
                        getView().onSuccess();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }

    @Override
    public void backConfirm(String id) {
        NetUtils.geApi().backConfirm(id)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<List<DropDownByEntryNoBean>>>() {
                    @Override
                    public void accept(BaseAppEntity<List<DropDownByEntryNoBean>> listBaseAppEntity) throws Exception {
                        getView().showMessage(listBaseAppEntity.getMsg());
                        getView().onSuccess();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }
}
